package com.zc.mychart.chart;

import android.graphics.Canvas;
import android.util.Log;

import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.renderer.YAxisRenderer;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.zc.mychart.model.KTimeType;
import com.zc.mychart.utils.ArithUtil;
import com.zc.mychart.utils.FormatUtil;

/**
 * Created by Administrator on 2018/2/28 0028.
 */

public class MyYAxisRender extends YAxisRenderer {


    public MyYAxisRender(ViewPortHandler viewPortHandler, YAxis axis, Transformer trans) {
        super(viewPortHandler, axis, trans);
    }

    @Override
    protected void drawYLabels(Canvas c, float fixedPosition, float[] positions, float offset) {
        for (int i = 0; i < mYAxis.mEntryCount; i++) {

            String text = mYAxis.getFormattedLabel(i);
            //处理去掉，
            if (text.contains(",")) {
                text = text.replace(",", "");
            }
//            if(mYAxis.getAxisDependency() == YAxis.AxisDependency.LEFT){
//                text = FormatUtil.formatDouble2(ArithUtil.mul(Double.valueOf(text),100));
//            }

            if (!mYAxis.isDrawTopYLabelEntryEnabled() && i >= mYAxis.mEntryCount - 1)
                return;

            int labelHeight = Utils.calcTextHeight(mAxisLabelPaint, text);
            float pos = positions[i * 2 + 1] + offset;

            if ((pos - labelHeight) < mViewPortHandler.contentTop()) {

                pos = mViewPortHandler.contentTop() + offset * 2.5f + 3;
            } else if ((pos + labelHeight / 2) > mViewPortHandler.contentBottom()) {
                pos = mViewPortHandler.contentBottom() - 3;
            }
//            Log.e("art YLabels ", text);
            if(MyLineChart.mKTimeType == KTimeType.MIN1){
                if(!text.contains("%")){
                    text = FormatUtil.formatDouble2(ArithUtil.mul(Double.parseDouble(text),MyLineChart.mWeight));
                }
                c.drawText(text, fixedPosition, pos, mAxisLabelPaint);
            }else{
                if(!text.contains("%")){
                    text = FormatUtil.formatDouble2(ArithUtil.mul(Double.parseDouble(text),MyLineChart.mWeight));
                    c.drawText(text, fixedPosition, pos, mAxisLabelPaint);
                }
            }
        }
    }
}
